export const nodeSize: number = 8;
// 自定义节点类
export class NodePoint {
  private _size: number = nodeSize; // 节点大小
  private _shape: string = "node-point";
  private _id: string = "";
  private _x: number = 0;
  private _y: number = 0;
  private _data: object = {};

  get size() {
    return this._size;
  }
  get shape() {
    return this._shape;
  }
  get id() {
    return this._id;
  }
  get x() {
    return this._x;
  }
  get y() {
    return this._y;
  }
  get data() {
    return this._data;
  }

  public getModel() {
    return {
      id: this.id,
      shape: this.shape,
      x: this.x,
      y: this.y,
      zIndex: 1,
      width: this.size,
      height: this.size,
      ports: {
        groups: {
          group1: {
            zIndex: 10,
            position: {
              name: "absolute",
            },
          },
        },
        items: [
          {
            id: "group1",
            group: "group1",
            args: {
              x: this.size / 2,
              y: this.size / 2,
            },
            attrs: {
              circle: {
                fill: "#fff",
                stroke: "#fff",
                magnet: false,
                strokeWidth: 2,
                r: this.size / 2,
              },
            },
          },
        ],
      },
      data: this.data,
    };
  }
  public setData: Function = (options: { id: string; x: number; y: number; data: object }) => {
    for (const key in options) {
      if (Object.prototype.hasOwnProperty.call(options, key)) {
        if (typeof options[key] === "object") {
          Object.assign(this[`_${key}`], options[key]);
        } else {
          this[`_${key}`] = options[key];
        }
      }
    }
  };
}
